import {
	defineStore
} from "pinia";

const useUserStore = defineStore("User", {
	persist: {
		key: "user",
		paths: ["uid", "userInfo", 'token', 'openId', 'Exam', 'isPrompt'],
	},
	state: () => {
		return {
			uid: null,
			userInfo: {},
			token: "",
			openId: '',
			Exam:null,
		    isPrompt:true
		};
	},
	actions: {
		logout() {
			this.$patch((state) => {
				state.uid = null;
				state.userInfo = {};
			});
			uni.clearStorageSync();
		},
		setUid(data){
			this.$patch((state) => {
				state.uid = data;
			});
		},
		setLoginInfo(data) {
			this.$patch((state) => {
				state.userInfo = data?.data || {};
			});
		},
		setOpenId(data) {
			this.$patch(state => {
				state.openId = data
			})
		},
	}
})

export default useUserStore;